package com.canbot.u05.activity.reception;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;

import com.canbot.u05.R;
import com.canbot.u05.socket.MsgSendUtils;
import com.canbot.u05.socket.MsgType;

/**
 * 迎宾模式主入口
 */
public class ReceptionEnterActivity extends ReceptionBaseActivity {


        private GridView mGridView;

        private int[] icon_ids = {R.drawable.icon_men_welcome_selector};

        private String[] names = {"门童接待"};

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                //                setContentView(R.layout.act_usher_enter);
                setContentView(R.layout.activity_reception_setting);
                mGridView = (GridView) findViewById(R.id.gridView);

                initData();
        }

        public void initData() {
                mGridView.setAdapter(new OfficeSettingAdapter());
                mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                itemClick(position);
                        }
                });
        }

        /**
         * GridView item 点击处理
         *
         * @param position gridView position
         */
        private void itemClick(int position) {
                switch (position) {
                        case 0:
                                userMenWelcome();
                                break;
                }
        }

        /**
         * 返回
         */
        public void usherBack(View view) {
                finish();
        }

        /**
         * 门童接待
         */
        public void userMenWelcome() {
//                MsgSendUtils.sendStringMsg(MsgType.SEND_PAD_MEETING_START, "handSetting");
                Intent intent = new Intent(this, ReceptionModeSettingActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
        }

        /**
         * 门卫
         */
        public void usgerGuard() {
        }


        @Override
        protected void onResume() {
                super.onResume();
                MsgSendUtils.sendStringMsg(MsgType.EYE_MOTION, "14");
        }

        @Override
        protected void onPause() {
                super.onPause();

        }

        private class OfficeSettingAdapter extends BaseAdapter {

                @Override
                public int getCount() {
                        return icon_ids.length;
                }

                @Override
                public Object getItem(int position) {
                        return position;
                }

                @Override
                public long getItemId(int position) {
                        return position;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                        ViewHolder mHolder;
                        if (convertView == null) {
                                mHolder = new ViewHolder();
                                convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_office_setting, parent, false);

                                mHolder.btn = (Button) convertView.findViewById(R.id.btn);
                                mHolder.name = (TextView) convertView.findViewById(R.id.name);
                                convertView.setTag(mHolder);
                        }
                        else {
                                mHolder = (ViewHolder) convertView.getTag();
                        }

                        if (getCount() == 1) {
                                mGridView.setNumColumns(1);
                                convertView.setLayoutParams(new GridView.LayoutParams(mGridView.getWidth(), mGridView.getHeight()));
                        }

                        mHolder.btn.setBackgroundResource(icon_ids[position]);
                        mHolder.name.setText(names[position]);

                        return convertView;
                }

        }

        static class ViewHolder {

                private Button btn;

                private TextView name;
        }

}
